package com.atguigu.gulimallsearch.controller;

import com.atguigu.gulimallsearch.service.MallSearchService;
import com.atguigu.gulimallsearch.vo.SearchParam;
import com.atguigu.gulimallsearch.vo.SearchResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

@Controller
public class SearchController {

    @Autowired
    MallSearchService mallSearchService;

    @GetMapping(value = {"/list.html"})
    public String listPage(SearchParam searchParam, Model model, HttpServletRequest request) throws IOException {//通过 首页检索条件 或 分类  查询页面
        searchParam.set_queryString(request.getQueryString());
        SearchResult result = mallSearchService.search(searchParam);
        //往域对象传值
        model.addAttribute("result",result);

        return "list";
    }
}
